package com.shaohai.live.utils;

import android.app.Activity;
import android.content.Context;
import android.os.IBinder;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public class DeviceHelper {
    //获取输入法打开的状态
    public static boolean isShowingInputWindow(Context context) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        return imm.isActive();//isOpen若返回true，则表示输入法打开
    }

    public static void showInputWindow(Context context, View binder) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInputFromInputMethod(binder.getWindowToken(), 0);
    }

    public static void toggleInputWindow(Context context, View binder) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInputFromWindow(binder.getWindowToken(), 0, InputMethodManager.HIDE_NOT_ALWAYS);
    }

    public static void hideInputWindow(Context context, View binder) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(binder.getWindowToken(), 0);
    }
}
